package com.example.school.controller.user;


import com.example.school.dto.UserLoginDto;
import com.example.school.dto.UserTiedStudentDto;
import com.example.school.service.UserService;
import com.example.school.utils.common.enums.Code;
import com.example.school.utils.common.result.Result;
import com.example.school.utils.config.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/user")
public class userController {

    @Autowired
    private UserService userService;

    @PostMapping("/user_login")
    public Result userLogin(@RequestBody UserLoginDto dto){
        return userService.userLogin(dto);
    }

    @GetMapping("/get_user")
    public Result getUser(){
        return userService.getUser();
    }

    @PostMapping("/tied_student")
    public Result tiedStudent(@RequestBody UserTiedStudentDto dto){
        return userService.tiedStudent(dto);
    }

    @GetMapping("/user_login_out")
    public Result userLoginOut(){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        BaseContext.removeCurrentId();
        return Result.okResult(Code.SUCCESS);
    }

}
